package com.pango.core.paginator.json;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.pango.core.paginator.domain.PageList;

/**
 * @author miemiedev
 */
@SuppressWarnings("rawtypes")
public class PageListJsonSerializer extends JsonSerializer<PageList> {
    @SuppressWarnings("unchecked")
	@Override
    public void serialize(PageList value, JsonGenerator jgen, SerializerProvider provider) throws IOException, JsonProcessingException {
        Map<String,Object> map = new HashMap<String, Object>();
        //针对EasyUi修改
        map.put("total", value.getPaginator().getTotalCount());
        map.put("rows" , new ArrayList(value));
        ObjectMapper mapper = new ObjectMapper();
        mapper.writeValue(jgen, map);
    }
}
